package com.bi.design.mqtt.borker.store.session;

import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


@Component
public class SessionStoreService implements ISessionStoreService {
    private static Map<String, SessionStore> CACHE = new ConcurrentHashMap<>();

    @Override
    public void put(String clientId, SessionStore sessionStore, int expire) {
        CACHE.put(clientId, sessionStore);
    }

    @Override
    public void put(String clientId, SessionStore sessionStore) {
        CACHE.put(clientId, sessionStore);
    }

    @Override
    public void expire(String clientId, int expire) {
        CACHE.remove(clientId);
    }

    @Override
    public SessionStore get(String clientId) {
        return CACHE.get(clientId);
    }

    @Override
    public boolean containsKey(String clientId) {
        return CACHE.get(clientId) != null;
    }

    @Override
    public void remove(String clientId) {
        CACHE.remove(clientId);
    }
}
